// index.js
const app = getApp()
const SERVER = require('../../utils/index');
Page({
  data: {
    swiperList: [],
    infoList:[],
    lotList:[],
    specList:[],
    liveList:[],
    switch1Checked:'',
    buttonTop: 0,
 buttonLeft: 0,
 windowHeight: '',
 windowWidth: '',
 startPoint:'',
 //角标显示数字
 corner_data:0,
   
  },
 
  tiaozhuan(){
    wx.navigateTo({
      url: '/pages/uesename/username'
    })
  },
  //点击跳转直播
  live(e){
    if(wx.getStorageSync('token')==''){
      wx.navigateTo({
        url: '/pages/uesename/username'
      })
    }else{
      wx.navigateTo({
        url: '/pages/live/live?id='+e.currentTarget.dataset.id
      })
    }
  },
  // tiaozhuan(){
   
  // },
  /* 搜索 */
  search() {
    if(wx.getStorageSync('token')==''){
      wx.navigateTo({
        url: '/pages/uesename/username'
      })
    }else{
      wx.navigateTo({
        url: '/pages/search/search'
      })
    }
   
  },
  //热门专场
  Special(e){
    if(wx.getStorageSync('token')==''){
      wx.navigateTo({
        url: '/pages/uesename/username'
      })
    }else{
      wx.navigateTo({
        url: '/pages/Special/Special?id='+e.currentTarget.dataset.id
      })
    }
  },
  /* 信息 */
  message() {
    if(wx.getStorageSync('token')==''){
      wx.navigateTo({
        url: '/pages/uesename/username'
      })
    }else{
      wx.navigateTo({
        url: '/pages/message/message'
      })
    }
    
  },
  dynamic(e){
    if(wx.getStorageSync('token')==''){
      wx.navigateTo({
        url: '/pages/uesename/username'
      })
    }else{
      wx.navigateTo({
        url: '/pages/info/info?img='+e.currentTarget.dataset.img
      })
    }
   
  },
  /* 拍品品详情 */
  shopDetail(e) {
    if(wx.getStorageSync('token')==''){
      wx.navigateTo({
        url: '/pages/uesename/username'
      })
    }else{
   
 wx.navigateTo({
      url: '/pages/hotpage/hotpage?id='+e.currentTarget.dataset.id
    })
    }

   
  },
  //可拖动悬浮按钮点击事件
 btn_Suspension_click:function(){
  //这里是点击购物车之后将要执行的操作
  wx.navigateTo({
    url: '/pages/mineLot/mineLot'
  })
  },
  //以下是按钮拖动事件
  buttonStart: function (e) {
    this.setData({
      startPoint:e.touches[0]
    })
  // let startPoint = e.touches[0]//获取拖动开始点
  },
  buttonMove: function (e) {
  var endPoint = e.touches[e.touches.length - 1]//获取拖动结束点
  //计算在X轴上拖动的距离和在Y轴上拖动的距离
  var translateX = endPoint.clientX - this.data.startPoint.clientX
  var translateY = endPoint.clientY - this.data.startPoint.clientY
  this.data.startPoint = endPoint//重置开始位置
  var buttonTop = this.data.buttonTop + translateY
  var buttonLeft = this.data.buttonLeft + translateX
  //判断是移动否超出屏幕
  if (buttonLeft+50 >= this.data.windowWidth){
   buttonLeft = this.data.windowWidth-50;
  }
  if (buttonLeft<=0){
   buttonLeft=0;
  }
  if (buttonTop<=0){
   buttonTop=0
  }
  if (buttonTop + 50 >= this.data.windowHeight){
   buttonTop = this.data.windowHeight-50;
  }
  this.setData({
   buttonTop: buttonTop,
   buttonLeft: buttonLeft
  })
  },
  buttonEnd: function (e) {
  },
  onLoad: function (options) {
    this.setData({
      corner_data:3
     })
     // 获取购物车控件适配参数
     var that =this;
     wx.getSystemInfo({
      success: function (res) {
      console.log(res);
      // 屏幕宽度、高度
      console.log('height=' + res.windowHeight);
      console.log('width=' + res.windowWidth);
      // 高度,宽度 单位为px
      that.setData({
       windowHeight: res.windowHeight,
       windowWidth: res.windowWidth,
       buttonTop:res.windowHeight*0.50,//这里定义按钮的初始位置
       buttonLeft:res.windowWidth*0.80,//这里定义按钮的初始位置
      })
      }
     })
    console.log(wx.getStorageSync('switch1Checked'))
    var that=this
    wx.request({//首页数据
      url: '' + SERVER.SERVER_DIMAIN + '/customer/homepage/index', 
      data: {
     
      },
      header: {
        'content-type': 'application/json' 
      },
      method: 'get',
      success: function (res) {
        console.log(res)
       that.setData({
         swiperList:res.data.data.bannerList,
         infoList:res.data.data.infoList,
         lotList:res.data.data.lotList,
         specList:res.data.data.specList,
         liveList:res.data.data.liveList
       })
  
       
      }
    });
  },
  onReady: function () {
    this.setData({
      switch1Checked:true
    })
  },
  onShow: function () {
this.setData({
  switch1Checked:wx.getStorageSync('switch1Checked')
})
    
  }
})
